package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.PartnerCustomerVO;
import com.yunxi.sat.service.PartnerCustomerDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 渠道客户关系 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/admin/partnerCustomer")
@Api(tags = "sat:partnerCustomer", description = "渠道客户关系接口")
public class PartnerCustomerController {
    private static final Logger logger = LoggerFactory.getLogger(PartnerCustomerController.class);

    @Autowired
    PartnerCustomerDubboService partnerCustomerDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(PartnerCustomerVO partnerCustomerVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(partnerCustomerDubboService.findPageByVO(partnerCustomerVO, pageNum, pageSize,loginInfo));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "partnerCustomerId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String partnerCustomerId, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(partnerCustomerDubboService.getById(partnerCustomerId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody PartnerCustomerVO partnerCustomerVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerCustomerDubboService.saveOrUpdate(partnerCustomerVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerCustomerDubboService.del(list,loginInfo.getUserCode());
        return ResponseUtil.ok("success");
    }

}
